import time
from selenium.webdriver.common.by import By
from selenium import webdriver
from UI.Base.Base import Base


class Page(Base):
    #搜索框
    wx_loc=(By.ID,'weixinch')
    def wx(self):
        return self.text(self.wx_loc)

    search_loc = (By.ID, 'query')
    def search(self):
        self.send_keys(self.search_loc,'软件测试自动化')
        self.enter(self.search_loc)

    dy2_loc=(By.PARTIAL_LINK_TEXT,'测试')
    def dy(self):
        return self.text(self.dy2_loc)


    all_loc=(By.ID,'main')
    def dy_2(self):
        return self.text(self.all_loc)

    next_loc=(By.ID,'sogou_next')
    def next(self):
        self.click(self.next_loc)

    def dy_4(self):
        return self.text(self.all_loc)




    def luoji_01_search(self):
        self.get_url('https://www.sogou.com/')
        time.sleep(2)
        dy1=self.wx()
        print(dy1)
        assert dy1=='微信'
        print("断言标签'微信'成功\n\n")
        self.search()
        time.sleep(2)
        dy2=self.dy()
        print('页面显示有效内容为:' + dy2)
        assert '测试' in dy2
        print("断言搜索结果包含'测试'成功\n\n")
        dy3=self.dy_2()
        print(dy3)
        assert '软件测试' in dy3
        print("断言标题包含关键字'软件测试'成功\n\n")
        self.implicitly_wait(3)
        self.next()
        dy4=self.dy_4()
        print(dy4)
        assert '软件测试' in dy4
        print("断言第二页标题包含关键字'软件测试'成功\n\n")
        time.sleep(2)
